import {
  getData
} from './request';

//通过外界传入store来修改
export default async (store) => {
  //参数1：consName	星座名称，如:双鱼座
  //参数2：type	运势类型：today,tomorrow,week,month,year
  const consName = store.state.consName,
    field = store.state.field;

  //获取后端数据
  const data = await getData(consName, field);

  /**
   * console.log(data);
   * {
   *   QFriend: "金牛座"
   *   all: "80",
   *   color: "淡蓝色",
   *   date: 20211130,
   *   datetime: "2021年11月30日",
   *   error_code: 0,
   *   health: "80",
   *   love: "85",
   *   money: "70",
   *   name: "白羊座",
   *   number: 0,
   *   resultcode: "200",
   *   summary: "今天会有过去的朋友或者...多问对方一些具体信息。",
   *   work: "65"
   * }
   */

  //success: error_code: 0
  if (data.error_code !== 0) {
    console.log('errorCode has been modified in state!');
    store.commit('setErrorCode', data.error_code);
    return;
  }

  //将data保存到state里
  store.commit('setData', data);

  // console.log(store.state);

  // return data;
}